package pretice.p2;

import java.util.Random;

//抢红包
public class Mythread extends Thread{
    private  static  double money=100;
    private static int count=3;
    private  final double MIN_MONEY=0.01;

    @Override
    public void run() {
       synchronized (Mythread.class){
           double price=0;
           if (count<1){
               System.out.println(getName()+"没抢到红包");
               return;
           }
           if (count==1){
                   price=money;
               }else {
               double range=money- MIN_MONEY  * (count-1);
               Random random=new Random();
               price=random.nextDouble()*range;
               if (price<MIN_MONEY){
                   price=MIN_MONEY;
               }
           }
           money=money-price;
           count--;
           System.out.println(getName()+"抢到了"+price+"元");


       }
    }
}
